package com.itheima;

import cn.hutool.core.codec.Base64;
import com.baidu.aip.face.AipFace;
import org.json.JSONObject;

public class Sample {
    //设置APPID/AK/SK
    public static final String APP_ID = "25283923";
    public static final String API_KEY = "RWohyC33826G208OPDPQTOCf";
    public static final String SECRET_KEY = "AbNhbkaa0d2HTm4zyEqIeIw2wMbtnaZd";

    public static Boolean detectFace(byte[] imageBytes) {
        // 初始化一个AipFace
        AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 人脸检测
        JSONObject res = client.detect(Base64.encode(imageBytes), "BASE64", null);
        return res.getString("error_msg").equalsIgnoreCase("SUCCESS");
    }
}